<?php
namespace Admin\Controller;
use Think\Controller;
class YuyueController extends CommonController {
	//预约定制
    public function index()
    {
        $yuyue = M('xuqiu'); // 实例化User对象
        $count      = $yuyue->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出

        //查询keyword动作
        $keyword = I('get.keyword');
        if (!empty($keyword)) {
            if (is_numeric($keyword)) {
                $sql = "select * from xuqiu where phone='{$keyword}' limit ". $Page->firstRow.','.$Page->listRows;
            }else {
                $sql = "select * from xuqiu where name='{$keyword}' limit ". $Page->firstRow.','.$Page->listRows;
            }
        }else {
            $sql = 'select * from xuqiu limit '. $Page->firstRow.','.$Page->listRows;
        }
        $yuyue = M()->query($sql);
        $this->assign('yuyue',$yuyue);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出

        $this->display();
    }

    //处理状态 设为处理1
    public function is_ok()
    {
        $id = I('post.id');
        $res = M('xuqiu')->where(array('id'=>$id))->setField('is_ok',1);
        if ($res) {
            $arr = array(
                'error' => 1 ,
                'info' => '预定处理成功'
                );
            echo json_encode($arr);
        }else {
            $arr = array(
                'error' => 0 ,
                'info' => '预定处理失败'
                );
            echo json_encode($arr);
        }
    }

    //删除
    public function delete()
    {
        $id = I('post.id');
        $res = M('xuqiu')->delete($id);
        if ($res) {
            $arr = array(
                'error' => 1 ,
                'info' => '预定删除成功'
                );
            echo json_encode($arr);
        }else {
            $arr = array(
                'error' => 0 ,
                'info' => '预定删除失败'
                );
            echo json_encode($arr);
        }
    }

    //评论列表
    public function comm()
    {
        $comm = M('comm'); // 实例化User对象
        $count      = $comm->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出

        //查询keyword动作
        $keyword = I('get.keyword');
        if (!empty($keyword)) {
            if (is_numeric($keyword)) {
                $sql = "select * from comm where goods_id='{$keyword}' limit ". $Page->firstRow.','.$Page->listRows;
            }else {
                $sql = "select * from comm where goods_name='{$keyword}' limit ". $Page->firstRow.','.$Page->listRows;
            }
        }else {
            $sql = 'select * from comm limit '. $Page->firstRow.','.$Page->listRows;
        }
        $comm = M()->query($sql);
        $this->assign('comm',$comm);// 赋值数据集
        $this->assign('page',$show);// 赋值分页输出

        $this->display();
    }

    //审核 为1
    public function is_shenhe()
    {
        $id = I('post.id');
        $res = M('comm')->where(array('id'=>$id))->setField('is_shenhe',1);
        if ($res) {
            $arr = array(
                'error' => 1 ,
                'info' => '审核成功'
                );
            echo json_encode($arr);
        }else {
            $arr = array(
                'error' => 0 ,
                'info' => '审核失败'
                );
            echo json_encode($arr);
        }
    }
    //删除
    public function comm_del()
    {
        $id = I('post.id');
        $res = M('comm')->delete($id);
        if ($res) {
            $arr = array(
                'error' => 1 ,
                'info' => '评论删除成功'
                );
            echo json_encode($arr);
        }else {
            $arr = array(
                'error' => 0 ,
                'info' => '评论删除失败'
                );
            echo json_encode($arr);
        }
    }



}